<template>
  <u-count-down :time="time" format="DD:HH:mm:ss" autoStart @onChange="onChange">
    <u-count-down :time="time" format="DD天HH:mm:ss" autoStart></u-count-down>
    <!-- <view class="time">
      <text class="time__item">{{ timeData.day }}&nbsp;天</text>
      <text class="time__item">{{ timeData.hour }}&nbsp;时</text>
      <text class="time__item">{{ timeData.minute }}&nbsp;分</text>
      <text class="time__item">{{ timeData.second }}&nbsp;秒</text>
    </view> -->
  </u-count-down>
</template>

<script>
  export default {
    props: {
      endTimestamp: Number,
      startTime: String,
      duration: Number
    },
    data() {
      return {
        currentTimestamp: 0,
        timeData: {
          day: 0,
          hour: 0,
          minute: 0,
          second: 0
        }
      }
    },
    computed: {
      // 倒计时时长
      time() {
        return this.endTimestamp - this.currentTimestamp
      },
      // day() {
      //   return Math.floor((this.endTimestamp - this.currentTimestamp) / 1000 / 60 / 60 / 24)
      // },
      // hour() {
      //   return Math.floor((this.endTimestamp - this.currentTimestamp) / 1000 / 60 / 60 % 24)
      // },
      // minute() {
      //   return Math.floor((this.endTimestamp - this.currentTimestamp) / 1000 / 60 % 60)
      // },
      // second() {
      //   return Math.floor((this.endTimestamp - this.currentTimestamp) / 1000 % 60)
      // }
    },
    methods: {
      onChange(e) {
        console.log(e)
        this.timeData = e
      }
    },
    mounted() {
      this.$http.get('/date').then(res => {
        console.log(res)
        this.currentTimestamp = res.data.timestamp
        console.log(this.currentTimestamp)
        console.log(new Date(this.currentTimestamp))
        console.log(this.endTimestamp)
        // this.timeData.day = Math.floor((this.endTimestamp - this.currentTimestamp) / 1000 / 60 / 60 / 24)
        // this.timeData.hour = Math.floor((this.endTimestamp - this.currentTimestamp) / 1000 / 60 / 60 % 24)
        // this.timeData.minute = Math.floor((this.endTimestamp - this.currentTimestamp) / 1000 / 60 % 60)
        // this.timeData.second = Math.floor((this.endTimestamp - this.currentTimestamp) / 1000 % 60)
      })
    }
  }
</script>

<style>
</style>
